package com.perselab.recipe.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name="ingredient")
public class Ingredient extends AbstractModel implements Auditable, Serializable {
	private static final long serialVersionUID = -682248270623059716L;
	
	private Long id;
	private String name;
	private String description;
	private Set<Image> images;
	private Date creationDate;
	private Date modificationDate;
	private int status;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	@Column
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Set<Image> getImages() {
		return images;
	}

	public void setImages(Set<Image> images) {
		this.images = images;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public void setModificationDate(Date modificationDate) {
		this.modificationDate = modificationDate;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@Override
	@Column(name="creation_date")
	public Date getCreationDate() {
		return this.creationDate;
	}

	@Override
	@Column(name="modification_date")
	public Date getModificationDate() {
		return this.modificationDate;
	}
	
	@Override
	@Column
	public int getStatus() {
		return this.status;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("id", this.id)
				.append("status", this.status)
				.append("name", this.name)
				.append("description", this.description)
				.toString();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(-1683787035, -1518184133)
				.append(this.id)
				.append(this.status)
				.append(this.name)
				.append(this.description)
				.toHashCode();
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof Role)) {
			return false;
		}

		final Ingredient rhs = (Ingredient) o;

		return new EqualsBuilder()
				.append(this.id, rhs.id)
				.append(this.status, rhs.status)
				.append(this.name, rhs.name)
				.append(this.description, rhs.description)
				.isEquals();
	}

}
